<template>
  <div class="box">
    <div class="test" ref="test"></div>
    <button @click="onClick">检测样式</button>
  </div>
</template>
<script>
const GREEN = 'rgb(0,128,0)'
const BLUE = 'rgb(0,0,255)'
const RED = 'rgb(255,0,0)'
const defaultClass = 'default'
export default {
  methods: {
    onClick() {
      const testRef = this.$refs.test
      // getComputedStyle() 方法获取元素样式值
      const style = getComputedStyle(testRef)
      const isExist = [GREEN, BLUE, RED].indexOf(style.backgroundColor)
      if (isExist === -1) {
        testRef.classList.add(defaultClass)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.test {
  width: 300px;
  height: 300px;
  border: 5px solid #424242;
  background-color: orange;
}
.default {
  background-color: green;
}
</style>
